package com.kaifamiao.io.d0922;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class TransferFileDemo {


    public static void main(String[] args) {
        try(FileReader reader = new FileReader("d:/io/reader.txt");
            BufferedReader br = new BufferedReader(reader);
            FileOutputStream fos = new FileOutputStream("d:/io/reader-gbk.txt");
        ){
            String line = br.readLine();
            System.out.println(line);

//            byte[] bytes = line.getBytes(StandardCharsets.UTF_8);
//            System.out.println(Arrays.toString(bytes));

            byte[] bytes = line.getBytes("gbk");
            System.out.println(Arrays.toString(bytes));
            System.out.println(new String(bytes, "gbk"));

            fos.write(bytes);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

